package com.bestcem.xm.txtanls.mq.receiver.biz.rabbit;

import com.bestcem.xm.txtanls.mq.receiver.biz.ReceiverService;
import com.bestcem.xm.txtanls.mq.receiver.biz.TxtanlsConsumers;
import com.bestcem.xm.txtanls.service.dto.mq.WorktableChanged;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

@Slf4j
@Component
@ConditionalOnProperty(prefix = "application", name = "mqType", havingValue = "rabbit")
public class RabbitConsumers implements TxtanlsConsumers {

    private ReceiverService receiverService;

    @Autowired
    public void setReceiverService(ReceiverService receiverService) {
        this.receiverService = receiverService;
    }

    /**
     * 更新所有使用对应数据源的文本分析项目的数据表名称
     */
    @Bean
    @Override
    public Consumer<GenericMessage<WorktableChanged>> worktableChanged() {
        return msg -> receiverService.worktableChanged(msg);
    }

    /**
     * 数据源更新字段时联动更新文本分析中的项目
     */
    @Bean
    @Override
    public Consumer<GenericMessage<WorktableChanged>> columnChanged() {
        return msg -> receiverService.columnChanged(msg);
    }
}
